#!/bin/env python
#_*_coding:utf8_*_
#author = 'swht'

import MySQLdb

'''
#
connet = MySQLdb.Connect(host='127.0.0.1',user='root',passwd='shen1234',db='swht')
cur = connet.cursor()
reCount = cur.execute('select id,name from userinfo;')

connet.commit()

cur.close()
connet.close()
print reCount
'''
'''
connet = MySQLdb.Connect(host='127.0.0.1',user='root',passwd='shen1234',db='swht')
cur = connet.cursor()
sql1 = "insert into userinfo(name,address) values(%s,%s)"
sql2 = "update userinfo set name = %s where id = 23"
# li =[
#      ('swht','CN'),
#      ('alex','USA'),
# ]
params = ('test')
# reCount = cur.executemany(sql1,li)
reCount1 = cur.execute('select * from userinfo')
reCount2 = cur.execute(sql2,params)
data = cur.fetchall()
connet.commit()
cur.close()
connet.close()
# print reCount
print reCount1
print reCount2
print data
'''
import MySQLdb

class MySqlHelper(object):
	def __init__(self):
		pass
	
	def Get_Dict(self,sql,params):
		connet = MySQLdb.Connect(host='127.0.0.1',user='root',passwd='shen1234',db='swht')
		cur = connet.cursor(cursorclass = MySQLdb.cursors.DictCursor)
		reCount1 = cur.execute(sql,params)
		data = reCount1.fetchall()
		cur.close()
		connet.close()
		return data
	def Get_One(self,sql,params):
		connet = MySQLdb.Connect(host='127.0.0.1',user='root',passwd='shen1234',db='swht')
		cur = connet.cursor(cursorclass = MySQLdb.cursors.DictCursor)
		reCount1 = cur.execute(sql,params)
		data = reCount1.fetone()
		cur.close()
		connet.close()
		return data


helper = MySqlHelper()
sql = "select * from userinfo where id > %s"
params = (1,)
simple_data = helper.Get_One(sql, params)
dict_data = helper.Get_Dict(sql, params) 